#include <iostream>

using namespace std;

bool check(int x) {
    if (x <= 0) {
        return false;
    }

    while (x) {
        int now = x % 10;
        if (now == 2 || now == 4) {
            return false;
        }
        x /= 10;
    }

    return true;
}

int main() {

    int res = 0;
    for (int i = 1; i <= 2019; ++i) {
        for (int j = i + 1; j <= 2019; ++j) {
            int k = 2019 - i - j;
            if (check(i) && check(j) && check(k) && i < j && j < k) {
                res++;
            }
        }
    }
    cout << res << endl;
    return 0;
}